package luanluan.control.managers 
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.utils.Dictionary;
	/**
	 * 层管理
	 * @author luanluan
	 */
	public class LayerManager 
	{
		private var _layerList:Dictionary;
		
		/**
		 * 初始化层
		 * @param	...layers	层类别(string) ， 排前的在下层
		 */
		public function init(...layers):void
		{
			for (var i:int = 0; i < layers.length; i++) 
			{
				var layer:Sprite = new Sprite();
				StageManager.instance.stage.addChild(layer);
				_layerList[layers[i]] = layer;
			}
		}
		
		/**
		 * 将显示对象添加到层
		 * @param	type	层类别
		 * @param	obj		待添加对象
		 */
		public function addToLayer(type:String , obj:DisplayObject):void
		{
			_layerList[type].addChild(obj);
		}
		
		/**
		 * 获取层
		 * @param	type
		 * @return
		 */
		public function getLayer(type:String):Sprite
		{
			return _layerList[type];
		}
		
		public function LayerManager(single:Single) 
		{
			if ( !single )
				throw(new Error( "请使用静态getter获取单例引用" ) );
				
			_layerList = new Dictionary();
		}
		
		private static var _instance:LayerManager = null;
		public static function get instance():LayerManager 
		{
			if (_instance == null)
				_instance = new LayerManager(new Single());
			return _instance;
		}
		
	}

}
class Single{}